package com.spider.admin.store.primary.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.spider.admin.conf.validator.UniqueValue;
import com.spider.admin.utils.CommonUtil;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.validation.annotation.Validated;

@Getter
@Setter

@Validated
@Entity
@Table(name = "t_account_service_permissions")

@Accessors(chain = true)

@Data
@EqualsAndHashCode(callSuper = true)
public class AccountServicePerm extends SuperVO {
    @Id
    @Column(name = "pid")
    private String pid;

    @Column(name = "account")
    @NotEmpty(message = "账户信息不能为空", groups = {Save.class, Update.class})
    private String account;
    @Transient
    private AccountInfo accountInfo;

    @Column(name = "service_id")
    @NotEmpty(message = "服务ID不能为空", groups = {Save.class, Update.class})
    private String serviceId;

    @Transient
    private ServiceInfo serviceInfo;

    @JsonIgnore
    @Column(name = "v_pid")
    @UniqueValue(domainClass = AccountServicePerm.class, fieldName = "vPid", message = "账户服务权限已经存在", groups = {Save.class, Update.class})
    private String vPid;

    private String getvPid(){
        return CommonUtil.md5(getAccount() + getServiceId());
    }
}

